
#include "TimeUtil.h"
#include <time.h>

namespace utils 
{

time_t TimeUtil::now()
{
    return ::time(nullptr);
}


std::string TimeUtil::getCurrentDateTime(const char* fmt)
{
    time_t n = TimeUtil::now(); 
    struct tm* t = ::localtime(&n);
    char buf[128] = "";
    ::strftime(buf, sizeof(buf), fmt, t);
    return buf;
}
 
void TimeUtil::getCurrentDateTime(int& year, int& month, int& day, int& hour, int& min, int& sec)
{
    time_t n = TimeUtil::now(); 
    struct tm* t = ::localtime(&n);
    year = t->tm_year + 1900;
    month = t->tm_mon;
    day = t->tm_mday;
    hour = t->tm_hour;
    min = t->tm_min;
    sec = t->tm_sec;
}  

} // namespace utils 
